package com.lyy.util;

import com.lyy.util.dto.SlrEmpSalary;

import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * @ClassName Test
 * @Description TODO
 * @Author louyangyi
 * @Date 2021/8/13 11:31
 **/
public class Test {

    public static void main(String[] args) throws Exception {
//        List<SlrEmpSalary> dataList=new ArrayList<SlrEmpSalary>();
//        SlrEmpSalary s1=new SlrEmpSalary(1,"001","lyy1","男");
//        SlrEmpSalary s2=new SlrEmpSalary(2,"002","lyy2","女");
//        SlrEmpSalary s3=new SlrEmpSalary(3,"003","lyy3","男");
//        dataList.add(s1);
//        dataList.add(s2);
//        dataList.add(s3);
//        OutputStream outputStream=new FileOutputStream("D:\\lyy.xlsx");
//        Map<String,String> map=new HashMap<String, String>();
//        map.put("0","女");
//        map.put("1","男");
//        ExcelUtils.ALL_SELECT_LIST_MAP.put(3,map);
//        ExcelUtils.exportExcel(outputStream, dataList,  SlrEmpSalary.class, ExcelUtils.ALL_SELECT_LIST_MAP, "人员信息导出",false);

//        InputStream in=new FileInputStream("D:\\test.xlsx");
//        List<SlrEmpSalary> objects = (List<SlrEmpSalary>) ExcelUtils.parseExcelToList(in, SlrEmpSalary.class,1);
//        objects.stream().forEach(r->print(r));

//        File uploadFile=new File("D:/test/11.txt");
//        File targetFile=new File("D:/test/22.txt");
//        File uploadFile=new File("D:/test/test.rar");
//        File targetFile=new File("D:/test/test2.rar");
//        File uploadFile=new File("D:/test/lyy.rar");
//        File targetFile=new File("D:/test/lyy2.rar");
//        File uploadFile=new File("D:/test/lyc.exe");
//        File targetFile=new File("D:/test/lyc2.exe");
//        File uploadFile=new File("D:/test/11.zip");
//        File targetFile=new File("D:/test/22.zip");
//        Long targetSize=uploadFile.getTotalSpace();
//        Long targetSize=uploadFile.length();
//        InputStream inputStream=new FileInputStream(uploadFile);
//        FileUtils.writeWithBlock(target,100l,inputStream,targetSize/3,3,0);
        //字节大小
//        System.out.println("uploadFile.length() = " + uploadFile.length());
//        FileUtils.blockWriteByMultiThread(targetFile,uploadFile,300,"m");
//        List<String> picPaths=new ArrayList<>();
//        picPaths.add("D:/test/11.png");
//        picPaths.add("D:/test/22.png");
//        FileUtils.zipFileByteBuffer("D:/test.zip",picPaths);

        TikTokUtils.tikTokPicDownload("9.43 GiP:/ 刘亦菲图集%刘亦菲 %美女 %壁纸 %清纯女神   https://v.douyin.com/NnjNacJ/ 复制此链接，打开Dou音搜索，直接观看视频！",
                "D:/test","pic");


//        FileUtils.unZipFile("D:/test.zip","D:/lyy/test");

//        File srcFile = new File("D:/test/test.zip");
//        File dstFile = new File("D:/test/test2.zip");
//        System.out.println("dstFile.getParentFile() = " + dstFile.getParentFile());
//        System.out.println("dstFile.getName() = " + dstFile.getName());
//        File logFile = new File(dstFile.getParentFile(),dstFile.getName() + ".log.raf");
//        RandomAccessFile logRaf = null;
//        long start = 0L;
//        try {
//            if(logFile.exists() && logFile.length() > 0){
//
//                Scanner sc = new Scanner(System.in);
//                System.out.println("上次拷贝结束:1 继续拷贝 0重新拷贝");
//                switch (sc.nextInt()) {
//                    case 1:
//                        logRaf = new RandomAccessFile(logFile, "rw");
//                        start = logRaf.readLong();
//                        copy(srcFile,dstFile,start);
//                        break;
//                    case 0:
//                        copy(srcFile,dstFile,start);
//                    default:
//                        System.out.println("输入错误,请输入一个 0或1 的数字 进行选择");
//                        break;
//                }
//
//            }else{
//                copy(srcFile,dstFile,start);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }



    }




    public static void copy(File srcDir,File dstFile,long start){

        long length = srcDir.length();
        File logRaf = new File(dstFile.getParentFile(),dstFile.getName() + ".log.raf");
        RandomAccessFile srcRandom = null;
        RandomAccessFile dstRandom = null;
        RandomAccessFile logRandom = null;
        try {

            if(length == 0){
                return;
            }

            srcRandom = new RandomAccessFile(srcDir, "rw");
            dstRandom = new RandomAccessFile(dstFile, "rw");
            logRandom = new RandomAccessFile(logRaf, "rw");

            long sum = start;
            int read = -1;
            int startavg = 0;
            byte b[] = new byte[1024];
            srcRandom.seek(start);
            while((read = srcRandom.read(b)) != -1){
                dstRandom.write(b,0,read);
                sum += read;

                int avg = (int)(100 * sum/length);
                if(avg > startavg){
                    System.out.println("已经完成了%:" + avg);
                    startavg = avg;
                }
                logRandom.seek(0);
                logRandom.writeLong(sum);
                Thread.currentThread().sleep(1);//降低写的速度 效果明显
            }


        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            if(logRandom != null){
                try {
                    logRandom.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(dstRandom != null){
                try {
                    dstRandom.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(srcRandom != null){
                try {
                    srcRandom.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            logRaf.delete();
        }
    }

    private static void print(SlrEmpSalary r) {
        System.out.println("SlrEmpSalary = " + r.toString());
    }
}
